// 模拟常用高阶函数：map every some

// map:对数组的元素进行遍历，并对每一项进行处理，处理结果并返回新数组
const map = (array, fn) => {
    let results = [] // 新数组
    for (let value of array) {
        results.push(fn(value))
    }
    return results
}
//测试map
let arr = [1,2,34,5,4]
arrMap = map(arr, v => v*v)
console.log('map',arrMap)

// every:判断数组的每一项是否符合条件，如果有一项不符合，就返回false；返回true/false
 const every = (array, fn) => {
     let result = true
     for(let value of array) {
         result = fn(value)
         if(!result) {
            break
         }
     }
     return result
 }

 // 测试every
 let  arrE = [122,33,11,14]
 let r = every(arrE, v=> v>10)
 console.log('every', r)

 //some:检测数组中的元素是否有一个满足数组中的条件,有一个满足返回
 const some = (array, fn) => {
    let result = false
    for(let value of array) {
        result = fn(value)
        if(result) {
            break
        }
    }
    return result
 }

 // 测试 
 let arrSome = [1,3,5,9]
 let sr = some(arrSome, v=>v % 2 === 0)
 console.log('some', sr)